/**
 * Created by Administrator on 2025/5/28.
 * */
#include "AIPCTrainController.h"
#include <iostream>
#include <thread>

BaseObject *createAIPCTrainController() {
    return new AIPCTrainController();
}

void destroyAIPCTrainController(BaseObject *p) {
    SAFE_DELETE(p);
}

AIPCTrainController::AIPCTrainController(){
}

AIPCTrainController::~AIPCTrainController() {
}

/* 如果使用了DDS_Reader或者DDS_Writer，则对应的input或者output前64个字节为DataFormat head首部 */
void AIPCTrainController::onCompute(buffer_table_t *input, buffer_table_t *output) {
    std::this_thread::sleep_for(std::chrono::milliseconds(1000));
    if (input->list[1]->valid) {
        int *pState = reinterpret_cast<int*>(input->list[1]->data);
        if (*pState > 0) {
            auto aiPCNetStateHolder = GlobalParameters::shareInstance()->findParameter("aiPCNetState");
            int *aiPCNetState = static_cast<int*>(GlobalParameters::shareInstance()->getValue(aiPCNetStateHolder, dynamic_cast<TaskModule*>(this)));
            *aiPCNetState = *pState;
            std::cout << "AIPCTrainController::onCompute 接收到状态更新：state=" << *pState << "; !!!!!!!!!!" << std::endl;
        }
    }
//
//
//
  /** 获取端口数据指针示例
   * const char *src0 = input->list[0]->data;
   * char *dest0 = output->list[0]->data;
   * */


  /** 计算示例
   * if (input->list[0]->valid) {
   *     memcpy(dest0, src0, std::min(input->list[0]->len, output->list[0]->len));
   *   }
   * */
}
